Skip to main content
Destroys the sandbox environment and resets conversation state for a specific room. Use this endpoint when a conversation session ends or to free up resources.

Endpoint

Path Parameters

string
required
Unique identifier for the room to clean up.

Response

Success (200 OK)

boolean
Always true when cleanup completes.
string
The room ID that was cleaned up.

Partial Success (207 Multi-Status)

Returned when cleanup completes but some operations failed:
boolean
Always true even when errors occur.
string[]
Array of error messages from failed cleanup operations (e.g., sandbox destruction failures).

Example Request

Example Response (Success)

Example Response (Partial Success)

Cleanup Operations

The endpoint performs the following cleanup tasks:
  1. Reset Agent State - Clears the conversation history (sets messages array to empty)
  2. Destroy Sandbox - Terminates the sandbox-{roomID} instance and removes its resources
Implementation reference from cf-worker/index.ts:244-266:

Error Handling

The cleanup endpoint is designed to be resilient:
  • Best-effort cleanup: Even if sandbox destruction fails, the agent state is still reset
  • Partial success reporting: Returns 207 status with error details rather than failing completely
  • No rollback: Successful cleanup operations are not reversed if later operations fail

Error Responses

404 Not Found

Returned when the room ID is missing from the URL path.

405 Method Not Allowed

Returned when using a method other than DELETE.

Use Cases

  • End of conversation session cleanup
  • Resource management and memory optimization
  • Resetting a room to initial state
  • Automated cleanup in test environments

Client Implementation Example

From internal/ai/client.go:106-125: